using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI.WebControls;
using System.Collections;

namespace emp.Utility
{
    public class PageUtil
    {
        public static int getGviewNewPage(GridView theGrid, int page)
        {

            int newPageIndex = 0;
            if (-2 == page)
            {
                TextBox txtNewPageIndex = null;
                GridViewRow pagerRow = theGrid.BottomPagerRow;
                if (null != pagerRow)
                {
                    txtNewPageIndex = pagerRow.FindControl("txtNewPageIndex") as TextBox;
                }
                if (null != txtNewPageIndex)
                {
                    try
                    {
                        newPageIndex = int.Parse(txtNewPageIndex.Text) - 1;
                    }
                    catch
                    {
                        newPageIndex = 0;
                    }
                }
            }
            else
            {
                newPageIndex = page;
            }
            newPageIndex = newPageIndex < 0 ? 0 : newPageIndex;
            newPageIndex = newPageIndex >= theGrid.PageCount ? theGrid.PageCount - 1 : newPageIndex;
            newPageIndex = newPageIndex < 0 ? 0 : newPageIndex;
            return newPageIndex;
        }

        public static void setPageCount(GridView theGrid,IList clist)
        {
            if (clist.Count > 0)
            {
                if (theGrid.BottomPagerRow != null)
                {
                    Label lbrecordcount = theGrid.BottomPagerRow.FindControl("lbrecordcount") as Label;
                    lbrecordcount.Text = clist.Count.ToString();
                }
            }
        }

        public static void setPageCount(GridView theGrid, int count)
        {
            if (count > 0)
            {
                if (theGrid.BottomPagerRow != null)
                {
                    Label lbrecordcount = theGrid.BottomPagerRow.FindControl("lbrecordcount") as Label;
                    if(lbrecordcount!=null) lbrecordcount.Text = count.ToString();
                }
            }
        }

        public static void setPageMouse(GridView theGrid)
        {
            for (int i = 0; i < theGrid.Rows.Count; i++)
            {


                string cssname = "dg_alternating";
                if (i % 2 == 0)
                {
                    cssname = "dg_item";
                }

                theGrid.Rows[i].Attributes.Add("onmouseout", "this.className = '" + cssname + "'");

                theGrid.Rows[i].Attributes.Add("onmouseover", "this.className = 'dg_alternating_new'");
            }
        }
    }

    
}
